/**-------------------------------- 工具 -----------------*/
var myDate = new Date();
function getCountDays() {
    var curDate = new Date();
    var curMonth = curDate.getMonth();
    curDate.setMonth(curMonth + 1);
    curDate.setDate(0);
    return curDate.getDate();
}
function getEveryDay() {
    var dayArry = [];
    var day = getCountDays();
    for (var k = 1; k <= day; k++) {
        dayArry.push(k);
    }
    
    return dayArry;
};
/**----------年统计 --------------*/
function chart2(data){
    var chart = echarts.init(document.getElementById('chart2'));
    var option = {
        title:{
            text:'年统计',
            textStyle:{
                color:'black'
            },
            left:100
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['十二月','一月','二月','三月',
            '四月','五月','六月','七月',
            '八月','九月','十月','十一月'],
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        yAxis: {
            type: 'value',
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        tooltip:{
          tigger:'item',
          formatter:"{b}: {c}条"
        },
        grid:{
            top:30,
            
            left:40
        },
        series: [{
            data: data,
            type: 'bar',
            areaStyle: {}
        }],
        color:['#0BC3A9']
    };
    chart.setOption(option);
}
/**----------月统计 --------------*/
function chart1(data,xAxis){
    var chart = echarts.init(document.getElementById('chart1'));
    var option = {
        title:{
            text:'月统计',
            textStyle:{
                color:'black'
            },
            left:100
        },
        tooltip:{
            tigger:'item',
            formatter:"{b}日: {c}条"
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: xAxis,
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        yAxis: {
            type: 'value',
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        grid:{
            top:30,
            left:40
        },
        series: [{
            data: data,
            type: 'line',
            areaStyle: {}
        }],
        color:['#0BC3A9']
    };
    chart.setOption(option);
}
/**----------日统计 --------------*/
function chart4(data){
    var chart = echarts.init(document.getElementById("chart4"));
    var option = {
        title:{
            text:'日统计',
            textStyle:{
                color:'black'
            },
            left:95
        },
        tooltip:{
          tigger:'item',
          formatter:"{b}: {c}条"
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ["24:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00",
            "08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00",
            "17:00","18:00","19:00",
            "20:00","21:00","22:00","23:00"],
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        yAxis: {
            type: 'value',
            axisLine:{
                lineStyle:{
                    color:'black'
                }
            }
        },
        grid:{
            top:35,
            left:45
        },
        series: [{
            data: data,
            type: 'line',
            areaStyle: {}
        }],
        color:['#0BC3A9']
    };
    chart.setOption(option);
}
/**----------热力图 --------------*/
/**-----------黑广播内容柱状图 -------*/
var chart5 = echarts.init(document.getElementById('chart5'));
option_chart5 = {
    title:{
        text:'年统计',
        // textStyle:{
        //     color:'#FFFFFF'
        // },
        left:100
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis:  {
        type: 'category',
        data: ['周一','周二','周三','周四','周五','周六','周日']
    },
    yAxis: {
        type: 'value',
    },
    series: [
        {
            name: '直接访问',
            type: 'bar',
            stack: '总量',
            data: [320, 302, 301, 334, 390, 330, 320]
        },
        {
            name: '邮件营销',
            type: 'bar',
            stack: '总量',
            data: [120, 132, 101, 134, 90, 230, 210]
        },
        {
            name: '联盟广告',
            type: 'bar',
            stack: '总量',
            data: [220, 182, 191, 234, 290, 330, 310]
        },
        {
            name: '视频广告',
            type: 'bar',
            stack: '总量',
            data: [150, 212, 201, 154, 190, 330, 410]
        },
        {
            name: '搜索引擎',
            type: 'bar',
            stack: '总量',
            data: [820, 832, 901, 934, 1290, 1330, 1320]
        }
    ]
};
chart5.setOption(option_chart5);
/**----------分类饼图-------------- */
function chart3(data,legend){
    var chart = echarts.init(document.getElementById("chart6"));
    var option = {
        title: {
            text: '分类统计',
            textStyle:{
              color:"black"
            },
            left:95,
          },
          tooltip:{
            tigger:'item',
            formatter:"{a}<br/>{b}: {c}条({d}%)"
          },
          legend:{
            orient:'vertical',
            data:legend,
            left:0,
            top:0,
            textStyle:{
                color:'black'
            }
          },
          series: [{
            name:"分类",
            type: 'pie',
            radius:'65%',
            data:data,
            label:{
                show:false,
                position:'inside',
                formatter:"{a}:{c}",
                color:'black'
            },
            itemStyle:{
                opacity:1
            },
            center:['63%','55%']
            // data: [5, 20, 36, 10, 10, 20,19,27]
          }],
          color:['#027B82','#0BC3A9','#9FE6B8','#FFDB5C','#B03A5B']
    };
    chart.setOption(option);
}
/**---------- axios　年统计 月统计 -----------*/
axios
.get('/d/bigscreen')
.then(function(response){
    // chart1(response.data.shuju.m_data,getEveryDay());
    chart2(response.data.shuju.y_data);
})
.catch(function(error){
    console.log(error)
})
/**---------- axios 时间统计 ----------------*/
// axios.get('/d/broadcast/time')
// .then(function(response){
//     data = response.data.time_list;
//     chart4(data);
// })
// .catch(function(error){
//     console.log(error)
// })
/**---------axios 分类统计 -------------------*/
axios
.get('/d/broadcast')
.then(function(response){
    var info_list = response.data.brocastlist;
    var legend = []
    var data_list = []
    for (var i=0;i<info_list.length;i++){
        if(legend.indexOf(info_list[i].category)==-1){
            legend[i] = info_list[i].category;
        }
    }
    for (var i=0;i<legend.length;i++){
        var data = new Object();
        data.name = legend[i]
        data.value = 0;
        data_list[i] = data; 
    }
    for (var i=0;i<info_list.length;i++){
        for (var j=0;j<data_list.length;j++){
            if(data_list[j].name == info_list[i].category){
                data_list[j].value += 1;
            }
        }
    }
    chart3(data_list,legend);
})
.catch(function(error){
    console.log(error)
})